// Copyright (c) Huoty, All rights reserved
// Author: Huoty <sudohuoty@163.com>
// CreateTime: 2021-05-20 14:02:08

package main

import "fmt"
import "time"

func main() {
    now := time.Now()                   // 获取当前时间
    fmt.Printf("now: %#v\n", now)

    timestamp := now.Unix()             // 时间戳
    // ntimestamp = .UnixNano()          // 纳秒级时间戳
    fmt.Printf("timestamp: %#v\n", timestamp)

    year := now.Year()      // 年
    month := now.Month()    // 月
    day := now.Day()        // 日
    hour := now.Hour()      // 小时
    minute := now.Minute()  // 分钟
    second := now.Second()  // 秒
    fmt.Printf("%d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second)

    timeObj := time.Unix(timestamp, 0)  // 将时间戳转为时间格式
    fmt.Printf("timeObj: %#v\n", timeObj)

    week := now.Weekday().String()  // 获取星期
    fmt.Printf("week: %#v\n", week)

    yearDay := now.YearDay()
    fmt.Printf("yearDay: %#v", yearDay)

    fmt.Println("")
}
